package com.wb.shuzu;

import java.util.Arrays;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月20日12:51
 */
public class Test11 {
    public static void main(String[] args) {
        test1();
        System.out.println("**************************");
        test2();
        System.out.println("**************************");
        test3();
        System.out.println("**************************");
        test4();
    }

    public static void test1() {
        // 定义一个int类型的二维数组,数组长度为3
        // 数组的每一个元素是一个int数组,长度为2
        int[][] nums = new int[3][2];
        nums[0][0] = 1;
        nums[0][1] = 2;
        nums[1][0] = 3;
        nums[1][1] = 4;
        nums[2][0] = 5;
        nums[2][1] = 6;
        for (int i = 0; i < nums.length; i++) {
            System.out.println(Arrays.toString(nums[i]));
        }
    }

    public static void test2() {
        int[][] arr = new int[3][];
        // 数组元素在赋值前必须指定长度
        arr[0] = new int[3];
        arr[0][0] = 1;
        arr[0][1] = 2;
        arr[0][2] = 3;
        arr[1] = new int[2];
        arr[1][0] = 4;
        arr[1][1] = 5;
        arr[2] = new int[4];
        arr[2][0] = 6;
        arr[2][1] = 7;
        arr[2][2] = 8;
        arr[2][3] = 9;
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
    }

    public static void test3() {
        int[][] arr = new int[][]{
                {1, 3, 5, 8},
                {2, 6},
                {6, 7, 8},
                {10, 11, 5, 12, 3}
        };
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
    }

    public static void test4() {
        int[][] arr = {
                {1, 3, 5, 8},
                {2, 6},
                {6, 7, 8},
                {10, 11, 5, 12, 3}
        };
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
    }
}
